package com.applet.service.impl;

import com.applet.common.constant.StateConstant;
import com.applet.mapper.StudioMapper;
import com.applet.pojo.dto.PublishStudioDTO;
import com.applet.pojo.entity.Studio;
import com.applet.pojo.dto.UpdateStudioDTO;
import com.applet.service.StudioService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author “XuShao”
 * @date 2024/12/20 15:29
 * @description
 */
@Service
public class StudioServiceImpl extends ServiceImpl<StudioMapper, Studio> implements StudioService {

    @Autowired
    private StudioMapper studioMapper;

    @Override
    public void addStudio(PublishStudioDTO publishStudioDTO) {
        Studio studio = new Studio();

        BeanUtils.copyProperties(publishStudioDTO, studio);

        studio.setCreateTime(LocalDateTime.now());
        studio.setUpdateTime(LocalDateTime.now());
        studio.setDeleted(StateConstant.ENABLE);

        studioMapper.insert(studio);
    }

    @Override
    public void updateStudio(UpdateStudioDTO updateStudioDTO) {
        Studio studio = new Studio();

        BeanUtils.copyProperties(updateStudioDTO, studio);

        studio.setUpdateTime(LocalDateTime.now());

        studioMapper.updateById(studio);
    }

    @Override
    public List<Studio> getStudioAll() {

        return studioMapper.selectList(null);
    }

}
